/* ------------------------------------------------------------------------*
 *
 * ------------------------------------------------------------------------*/

#include "debug.h"
#include "mbapp.h"
#include "com_def.h"
#include "sys_ext.h"
#include "bsp.h"

void USART3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));

//RS2
#define mbPORT                       USART3
#define mbURT_IRQn                   USART3_IRQn
#define mbISR                        USART3_IRQHandler
#define RCU_USART                    RCC_APB1Periph_USART3
#define RCU_USARTRST                 RCC_APB1Periph_USART3
#define mbObj                        mb.obj03
#define mbCmdBuff                    mb.CmdBuff03

//RS485 Dir-Pin
#define mbRxEnable()  
#define mbTxEnable()  

#include "bsp_mbport_common.h"
#include "mb_fun.h"

/*****************************************************************************//*!
*
* @brief   port.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
static void mb_port_hal_cfg(void)
{
    RCC_APB1PeriphClockCmd(RCU_USART, ENABLE);
    RCC_APB1PeriphResetCmd(RCU_USARTRST, ENABLE);
    RCC_APB1PeriphResetCmd(RCU_USARTRST, DISABLE);
}

/*****************************************************************************//*!
*
* @brief   mb object init.
*
* @param   none
*
* @return  TURE
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

static void mb_cb_set(void)
{
    mbObj.slave.reg_coils_cb = &smb_reg_coils_cb;
    mbObj.slave.reg_discrete_cb = &smb_reg_discrete_cb;
    mbObj.slave.reg_hold_cb = &smb_reg_holding_cb;
    mbObj.slave.reg_input_cb = &smb_reg_input_cb;

    mmb_cmd_buff_init(&mbObj, mbCmdBuff, 32, 16);

    mbObj.api = &mb_fun;
}

/*****************************************************************************//*!
* @brief    com modle init .
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void mb03_Init(mb_mode_type mbMode, uint32_t ulBaudRate, mb_parity_type eParity)
{
    nvic_irq_set(mbURT_IRQn,0x0F,0);

   mb_port_Init(mbMode, ulBaudRate, eParity);
}
